<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('流程审批')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sjcontract-add" th:object="${obj}">
    	<h4 class="form-header h4">基本信息</h4>
            <input name="id" th:field="*{id}" type="hidden">
            <input type="hidden" name="gcProjectid" id="gcProjectid" th:value="*{gcProjectid}">
        	<input type="hidden" name="projectId" id="projectId" th:value="*{projectId}">
        	<input type="hidden" name="orderNo" id="orderNo" th:value="*{orderNo}">
        	<input type="hidden" name="xmtype" id="xmtype" th:value="*{xmtype}">
        	<input name="fpjine" type="hidden" th:value="${fpjine}" >
        	<input name="ljzf" type="hidden" th:value="${kucljzf}" >
            <input type="hidden" id="approvename" name="approvename" th:value="${approvename}" />
        	<div class="form-group">    
                <label class="col-sm-2 control-label is-required">项目编号：</label>
                <div class="col-sm-2">
                    <input name="projectNo" th:field="*{projectNo}" class="form-control" type="text" autoComplete="off" readonly="readonly" required>
                </div>
                <label class="col-sm-2 control-label is-required">项目负责人：</label>
                <div class="col-sm-2">
                    <input name="xmfzr" th:field="*{xmfzr}" class="form-control" type="text" autoComplete="off" required readonly="readonly">
                </div>
                <label class="col-sm-2 control-label is-required">合同金额：</label>
                <div class="col-sm-2">
                    <input name="htzje" th:field="*{htzje}" class="form-control" type="text" autoComplete="off" required readonly="readonly">
                </div>
            </div>
            <div class="form-group">  
            	<label class="col-sm-2 control-label is-required">发票类型：</label>
                <div class="col-sm-2">
                	<input name="fpType" class="form-control" required type="text" autoComplete="off" th:field="*{fpType}" readonly="readonly">
                </div>
            	<label class="col-sm-2 control-label is-required">项目名称：</label>
                <div class="col-sm-2">
                    <input name="xmmc" th:field="*{xmmc}" class="form-control" type="text" autoComplete="off" required readonly="readonly">
                </div>  
            	<label class="col-sm-2 control-label is-required">单位名称：</label>
                <div class="col-sm-2">
                	<input name="ckdw" class="form-control" required type="text" autoComplete="off" th:field="*{ckdw}" readonly="readonly">
                </div>
            </div>
            <div class="form-group">
                 <label class="col-sm-2 control-label is-required">对接部门：</label>
                <div class="col-sm-2">
                    <input name="dept" class="form-control" type="text" th:field="*{dept}" autoComplete="off" readonly="readonly" required>
                    <input name="deptId" th:field="*{deptId}" type="hidden">
                </div>
                <label class="col-sm-2 control-label is-required">对接人：</label>
                <div class="col-sm-2">
                    <input name="owner" class="form-control" th:field="*{owner}" readonly="readonly" type="text" autoComplete="off" required>
                	<input name="ownerId" th:field="*{ownerId}" type="hidden">
                </div>
				<label class="col-sm-2 control-label is-required">项目所属：</label>
                <div class="col-sm-2">
                    <select name="authority" th:field="*{authority}" class="form-control" required readonly="readonly">
						<option th:each="cl:${deptlis}" th:value="${cl.deptId}" th:text="${cl.deptName}"></option>
					</select>
                </div>
			</div>
			<div class="form-group">    
				<label class="col-sm-2 control-label is-required">税金：</label>
                <div class="col-sm-2">
                    <input name="suij" th:field="*{suij}" readonly="readonly" class="form-control" required type="text" autoComplete="off" >
                </div> 
                <label class="col-sm-2 control-label is-required">付款单位：</label>
            	<div class="col-sm-2">
            		<select name="ztdw" th:field="*{ztdw}" class="form-control" th:with="type=${@dict.getType('sj_gongs')}" required readonly="readonly">
                    	<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                	</select>
                </div>
            </div>
            <h4 class="form-header h4" style="margin-top: 8px;margin-bottom: 0px;">表单项</h4>
            <div class="row" >
                <div class="col-sm-12">
				    <table id="bootstrap-table"></table>
                </div>
            </div>
        <h4 class="form-header h4" style="margin-top: 18px;">审核信息</h4>
        <div class="form-group">
            <label class="col-sm-2 control-label ">审批结果：</label>
            <div class="col-sm-4">
                <label class="radio-box">
                    <input type="radio" checked="" value="true" name="level3approve">同意</label>
                <label class="radio-box">
                    <input type="radio" value="false" name="level3approve">拒绝</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">审批意见：</label>
            <div class="col-sm-10">
                <textarea rows="5" name="fwshyj" class="form-control" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <input type="hidden"  name="status" id="status" >
                <input type="hidden"  name="id" id="id" th:value="${obj.id}">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:src="@{/ruoyi/base64.min.js?v=20231208}"></script>
    <script th:src="@{/js/jquery.tmpl.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-sjcontract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
    	if ($.validate.form()) {
        var taskid = $("#taskid").val();
        var check = document.querySelector("input[name='level3approve']:checked").value;
        if(check=="false"){
        	$("#status").val(4);
        }else{
        	$("#status").val(2);
        }
        var comment = $("textarea[name=fwshyj]").val();
        
        $.operate.save("edit4check", $('#form-sjcontract-add').serialize(), function(){
        	var json = {"level3approve": check, "level4": $("#approvename").val(), "comment": comment};
	        $.ajax({
	            url : prefix + "/completeTask/" + taskid,
	            type : "POST",
	            data : JSON.stringify(json), //转JSON字符串
	            dataType: 'json',
	            contentType:'application/json;charset=UTF-8', //contentType很重要
	            success : function(result) {
	                $.modal.msg("办理成功");
	                const parent = window.parent;
	                // 我的待办
	                const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
	                // 我的全部待办
	                const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
	                myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
	                myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
	                $.modal.closeTab();
	            }
	        });
	        
        });
    	}
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
    
    $(function() {
		var zilwj = $("#zbFilevo").val();
    	
    	var n=zilwj.split(",");
    	for(var i=0;i<n.length;i++){
//     		var url = "http://lkgnews.cn:8012/onlinePreview?url="+encodeURIComponent(Base64.encode(n[i]));
    		var url = n[i];
    		$("#zbFilelink").append("<a href='"+url+"' target='_blank' >"+n[i]+"</a><br>");
    	}
    	
    });
    
    $(function() {
    	var data = [[${obj.items}]];
    	
    	// 初始化数据, 可以由后台传过来
	    var options = {
	    	data: data,
            pagination: false,
	        showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
	        columns: [
	        {
	        	field: 'index',
	        	align: 'center',
	        	title: "序号",
	        	width: 50,
                formatter: function (value, row, index) {
                	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                	var columnId = $.common.sprintf("<input type='hidden' name='items[%s].xuh' value='%s'>", index, row.id);
                	return columnIndex + $.table.serialNumber(index) + columnId;
                }
            },
	        {
	            field: 'descs',
	            align: 'center',
	            title: '支付事项摘要说明',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input readonly='readonly' class='form-control descscount' type='text' autoComplete='off' name='items[%s].descs' value='%s'>", index, value);
	        		return html;
                }
	        },
//		        {
//		            field: 'fpType',
//		            align: 'center',
//		            title: '发票类型',
//		            width: '100',
//		            formatter: function(value, row, index) {
//		        		var data = [{ index: index, type: value }];
//		                return $("#itemFp").tmpl(data).html();
//                 }
//		        },
//		        {
//		            field: 'fpsl',
//		            align: 'center',
//		            title: '发票税率',
//		            width: '100',
//		            formatter: function(value, row, index) {
//		        		var data = [{ index: index, type: value }];
//		                return $("#itemSuilv").tmpl(data).html();
//                 }
//		        },
//		        {
//		            field: 'fangshi',
//		            align: 'center',
//		            title: '支付方式',
//		            width: 200,
//		            formatter: function(value, row, index) {
//		        		var data = [{ index: index, type: value }];
//		                return $("#itemType").tmpl(data).html();
//                 }
//		        },
	        {
	            field: 'jine',
	            align: 'center',
	            title: '支付金额',
	            width: 280,
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input readonly='readonly' class='form-control jinecount' type='text' autoComplete='off' name='items[%s].jine' value='%s'>", index, value);
	        		return html;
                }
	        },
	        {
	            field: 'memo',
	            align: 'center',
	            title: '备注',
	            width: 280,
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input readonly='readonly' class='form-control memocount' type='text' autoComplete='off' name='items[%s].memo' value='%s'>", index, value);
	        		return html;
                }
	        }]
	    };
	    $.table.init(options);
	});
    
    $.validator.addMethod("descscount", function(value, element) {
        return !this.optional(element);
    }, "支付事项摘要说明必填。");
    $.validator.addMethod("jinecount", function(value, element) {
        return !this.optional(element) && (value <= 10000000 && value >= 1);
    }, "支付金额长度区间1-10000000。");
    $.validator.addMethod("fangshicount", function(value, element) {
        return !this.optional(element);
    }, "支付方式必填。");
    
    function addRow() {
    	var count = $("#" + table.options.id).bootstrapTable('getData').length;
    	var row = {
            index: $.table.serialNumber(count),
            descs: "",
            jine: 0,
            fangshi: "",
            memo: "",
        }
    	sub.addColumn(row);
    }
</script>
</body>
</html>

<!-- 成本类型 -->
<script id="itemType" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='items[${index}].fangshi'>
    <option value="电汇" {{if type==="电汇"}}selected{{/if}}>电汇</option>
<option value="现金" {{if type==="现金"}}selected{{/if}}>现金</option>
<option value="承兑" {{if type==="承兑"}}selected{{/if}}>承兑</option>
<option value="转账" {{if type==="转账"}}selected{{/if}}>转账</option>
<option value="其他" {{if type==="其他"}}selected{{/if}}>其他</option>
</select>
</div>
</script>

<!-- 发票类型 -->
<script id="itemFp" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='items[${index}].fpType'>
	<option value="专用发票" {{if type==="专用发票"}}selected{{/if}}>专用发票</option>
    <option value="普通发票" {{if type==="普通发票"}}selected{{/if}}>普通发票</option>
<option value="其他选项" {{if type==="其他选项"}}selected{{/if}}>其他选项</option>
</select>
</div>
</script>

<!-- 税率 -->
<script id="itemSuilv" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='items[${index}].fpsl'>
    <option value="13" {{if type==="13"}}selected{{/if}}>13%</option>
	<option value="11" {{if type==="11"}}selected{{/if}}>11%</option>
	<option value="9" {{if type==="9"}}selected{{/if}}>9%</option>
	<option value="6" {{if type==="6"}}selected{{/if}}>6%</option>
	<option value="3" {{if type==="3"}}selected{{/if}}>3%</option>
	<option value="1" {{if type==="1"}}selected{{/if}}>1%</option>
	<option value="0" {{if type==="0"}}selected{{/if}}>0%</option>
</select>
</div>
</script>